README.standalone 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 slot numbers 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[XF_malloc] = my_malloc;
  13. gd->jt[XF_free] = my_free;
  14. Note that the pointers to the functions all have 'void *' type and
  15. thus the compiler cannot 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 and MIPS architectures use a
  18. dedicated register to hold the pointer to the 'global_data'
  19. structure: r2 on PowerPC, r8 on ARM and k0 on MIPS. The x86
  20. architecture does not use such a register; instead, the pointer to
  21. the 'global_data' structure is passed as 'argv[-1]' pointer.
  22. The application can access the 'global_data' structure in the same
  23. way as U-Boot does:
  24. DECLARE_GLOBAL_DATA_PTR;
  25. printf("U-Boot relocation offset: %x\n", gd->reloc_off);
  26. 3. The application should call the app_startup() function before any
  27. call to the exported functions. Also, implementor of the
  28. application may want to check the version of the ABI provided by
  29. U-Boot. To facilitate this, a get_version() function is exported
  30. that returns the ABI version of the running U-Boot. I.e., a
  31. typical application startup may look like this:
  32. int my_app (int argc, char *argv[])
  33. {
  34. app_startup (argv);
  35. if (get_version () != XF_VERSION)
  36. return 1;
  37. }
  38. 4. The default load and start addresses of the applications are as
  39. follows:
  40. Load address Start address
  41. x86 0x00040000 0x00040000
  42. PowerPC 0x00040000 0x00040004
  43. ARM 0x0c100000 0x0c100000
  44. MIPS 0x80200000 0x80200000
  45. For example, the "hello world" application may be loaded and
  46. executed on a PowerPC board with the following commands:
  47. => tftp 0x40000 hello_world.bin
  48. => go 0x40004
  49. 5. To export some additional function foobar(), the following steps
  50. should be undertaken:
  51. - Append the following line at the end of the include/_exports.h
  52. file:
  53. EXPORT_FUNC(foobar)
  54. - Add the prototype for this function to the include/exports.h
  55. file:
  56. void foobar(void);
  57. - Add the initialization of the jump table slot wherever
  58. appropriate (most likely, to the jumptable_init() function):
  59. gd->jt[XF_foobar] = foobar;
  60. - Increase the XF_VERSION value by one in the include/exports.h
  61. file
  62. 6. The code for exporting the U-Boot functions to applications is
  63. mostly machine-independent. The only places written in assembly
  64. language are stub functions that perform the jump through the jump
  65. table. That said, to port this code to a new architecture, the
  66. only thing to be provided is the code in the examples/stubs.c
  67. file. If this architecture, however, uses some uncommon method of
  68. passing the 'global_data' pointer (like x86 does), one should add
  69. the respective code to the app_startup() function in that file.
  70. Note that these functions may only use call-clobbered registers;
  71. those registers that are used to pass the function's arguments,
  72. the stack contents and the return address should be left intact.