blob: 3495f54f588474b1194a6f4da33f671caea6028b [file] [log] [blame]
wdenk27b207f2003-07-24 23:38:38 +00001Design Notes on Exporting U-Boot Functions to Standalone Applications:
2======================================================================
3
wdenk77846742003-07-26 08:08:08 +000041. The functions are exported by U-Boot via a jump table. The jump
5 table is allocated and initialized in the jumptable_init() routine
6 (common/exports.c). Other routines may also modify the jump table,
7 however. The jump table can be accessed as the 'jt' field of the
8 'global_data' structure. The slot numbers for the jump table are
9 defined in the <include/exports.h> header. E.g., to substitute the
10 malloc() and free() functions that will be available to standalone
11 applications, one should do the following:
wdenk27b207f2003-07-24 23:38:38 +000012
wdenk77846742003-07-26 08:08:08 +000013 DECLARE_GLOBAL_DATA_PTR;
wdenk27b207f2003-07-24 23:38:38 +000014
wdenk77846742003-07-26 08:08:08 +000015 gd->jt[XF_malloc] = my_malloc;
16 gd->jt[XF_free] = my_free;
wdenk27b207f2003-07-24 23:38:38 +000017
wdenk77846742003-07-26 08:08:08 +000018 Note that the pointers to the functions all have 'void *' type and
19 thus the compiler cannot perform type checks on these assignments.
wdenk27b207f2003-07-24 23:38:38 +000020
wdenk77846742003-07-26 08:08:08 +0000212. The pointer to the jump table is passed to the application in a
Mike Frysinger4c58eb52008-02-04 19:26:54 -050022 machine-dependent way. PowerPC, ARM, MIPS and Blackfin architectures
23 use a dedicated register to hold the pointer to the 'global_data'
24 structure: r29 on PowerPC, r8 on ARM, k0 on MIPS, and P5 on Blackfin.
25 The x86 architecture does not use such a register; instead, the pointer
26 to the 'global_data' structure is passed as 'argv[-1]' pointer.
wdenk27b207f2003-07-24 23:38:38 +000027
wdenk77846742003-07-26 08:08:08 +000028 The application can access the 'global_data' structure in the same
29 way as U-Boot does:
wdenk27b207f2003-07-24 23:38:38 +000030
wdenk77846742003-07-26 08:08:08 +000031 DECLARE_GLOBAL_DATA_PTR;
wdenk27b207f2003-07-24 23:38:38 +000032
wdenk77846742003-07-26 08:08:08 +000033 printf("U-Boot relocation offset: %x\n", gd->reloc_off);
wdenk27b207f2003-07-24 23:38:38 +000034
wdenk77846742003-07-26 08:08:08 +0000353. The application should call the app_startup() function before any
36 call to the exported functions. Also, implementor of the
37 application may want to check the version of the ABI provided by
38 U-Boot. To facilitate this, a get_version() function is exported
39 that returns the ABI version of the running U-Boot. I.e., a
40 typical application startup may look like this:
wdenk27b207f2003-07-24 23:38:38 +000041
wdenk77846742003-07-26 08:08:08 +000042 int my_app (int argc, char *argv[])
43 {
44 app_startup (argv);
45 if (get_version () != XF_VERSION)
46 return 1;
47 }
wdenk27b207f2003-07-24 23:38:38 +000048
wdenk77846742003-07-26 08:08:08 +0000494. The default load and start addresses of the applications are as
50 follows:
wdenk27b207f2003-07-24 23:38:38 +000051
Mike Frysinger4c58eb52008-02-04 19:26:54 -050052 Load address Start address
53 x86 0x00040000 0x00040000
54 PowerPC 0x00040000 0x00040004
55 ARM 0x0c100000 0x0c100000
56 MIPS 0x80200000 0x80200000
57 Blackfin 0x00001000 0x00001000
wdenk27b207f2003-07-24 23:38:38 +000058
wdenk77846742003-07-26 08:08:08 +000059 For example, the "hello world" application may be loaded and
60 executed on a PowerPC board with the following commands:
wdenk27b207f2003-07-24 23:38:38 +000061
wdenk77846742003-07-26 08:08:08 +000062 => tftp 0x40000 hello_world.bin
wdenk27b207f2003-07-24 23:38:38 +000063 => go 0x40004
64
wdenk77846742003-07-26 08:08:08 +0000655. To export some additional function foobar(), the following steps
66 should be undertaken:
wdenk27b207f2003-07-24 23:38:38 +000067
wdenk77846742003-07-26 08:08:08 +000068 - Append the following line at the end of the include/_exports.h
69 file:
wdenk27b207f2003-07-24 23:38:38 +000070
wdenk77846742003-07-26 08:08:08 +000071 EXPORT_FUNC(foobar)
wdenk27b207f2003-07-24 23:38:38 +000072
wdenk77846742003-07-26 08:08:08 +000073 - Add the prototype for this function to the include/exports.h
74 file:
wdenk27b207f2003-07-24 23:38:38 +000075
wdenk77846742003-07-26 08:08:08 +000076 void foobar(void);
wdenk27b207f2003-07-24 23:38:38 +000077
wdenk77846742003-07-26 08:08:08 +000078 - Add the initialization of the jump table slot wherever
79 appropriate (most likely, to the jumptable_init() function):
wdenk27b207f2003-07-24 23:38:38 +000080
wdenk77846742003-07-26 08:08:08 +000081 gd->jt[XF_foobar] = foobar;
wdenk27b207f2003-07-24 23:38:38 +000082
wdenk77846742003-07-26 08:08:08 +000083 - Increase the XF_VERSION value by one in the include/exports.h
84 file
wdenk27b207f2003-07-24 23:38:38 +000085
wdenk77846742003-07-26 08:08:08 +0000866. The code for exporting the U-Boot functions to applications is
87 mostly machine-independent. The only places written in assembly
88 language are stub functions that perform the jump through the jump
89 table. That said, to port this code to a new architecture, the
90 only thing to be provided is the code in the examples/stubs.c
91 file. If this architecture, however, uses some uncommon method of
92 passing the 'global_data' pointer (like x86 does), one should add
93 the respective code to the app_startup() function in that file.
wdenk27b207f2003-07-24 23:38:38 +000094
wdenk77846742003-07-26 08:08:08 +000095 Note that these functions may only use call-clobbered registers;
96 those registers that are used to pass the function's arguments,
97 the stack contents and the return address should be left intact.