blob: 885c92fb3a27d969c0b60bbbf2174dedcb2deccb [file] [log] [blame]
wdenk874ac262003-07-24 23:38:38 +00001Design Notes on Exporting U-Boot Functions to Standalone Applications:
2======================================================================
3
wdenkb8463562003-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:
wdenk874ac262003-07-24 23:38:38 +000012
wdenkb8463562003-07-26 08:08:08 +000013 DECLARE_GLOBAL_DATA_PTR;
wdenk874ac262003-07-24 23:38:38 +000014
wdenkb8463562003-07-26 08:08:08 +000015 gd->jt[XF_malloc] = my_malloc;
16 gd->jt[XF_free] = my_free;
wdenk874ac262003-07-24 23:38:38 +000017
wdenkb8463562003-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.
wdenk874ac262003-07-24 23:38:38 +000020
wdenkb8463562003-07-26 08:08:08 +0000212. The pointer to the jump table is passed to the application in a
Mike Frysinger60f09302008-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'
Robin Getz2773d5f2009-08-17 15:23:02 +000024 structure: r2 on PowerPC, r8 on ARM, k0 on MIPS, and P3 on Blackfin.
Wolfgang Denk7b2d8362008-02-15 00:06:18 +010025 The x86 architecture does not use such a register; instead, the
26 pointer to the 'global_data' structure is passed as 'argv[-1]'
27 pointer.
wdenk874ac262003-07-24 23:38:38 +000028
wdenkb8463562003-07-26 08:08:08 +000029 The application can access the 'global_data' structure in the same
30 way as U-Boot does:
wdenk874ac262003-07-24 23:38:38 +000031
wdenkb8463562003-07-26 08:08:08 +000032 DECLARE_GLOBAL_DATA_PTR;
wdenk874ac262003-07-24 23:38:38 +000033
wdenkb8463562003-07-26 08:08:08 +000034 printf("U-Boot relocation offset: %x\n", gd->reloc_off);
wdenk874ac262003-07-24 23:38:38 +000035
wdenkb8463562003-07-26 08:08:08 +0000363. The application should call the app_startup() function before any
37 call to the exported functions. Also, implementor of the
38 application may want to check the version of the ABI provided by
39 U-Boot. To facilitate this, a get_version() function is exported
40 that returns the ABI version of the running U-Boot. I.e., a
41 typical application startup may look like this:
wdenk874ac262003-07-24 23:38:38 +000042
wdenkb8463562003-07-26 08:08:08 +000043 int my_app (int argc, char *argv[])
44 {
45 app_startup (argv);
46 if (get_version () != XF_VERSION)
47 return 1;
48 }
wdenk874ac262003-07-24 23:38:38 +000049
wdenkb8463562003-07-26 08:08:08 +0000504. The default load and start addresses of the applications are as
51 follows:
wdenk874ac262003-07-24 23:38:38 +000052
Mike Frysinger60f09302008-02-04 19:26:54 -050053 Load address Start address
54 x86 0x00040000 0x00040000
55 PowerPC 0x00040000 0x00040004
56 ARM 0x0c100000 0x0c100000
57 MIPS 0x80200000 0x80200000
58 Blackfin 0x00001000 0x00001000
wdenk874ac262003-07-24 23:38:38 +000059
wdenkb8463562003-07-26 08:08:08 +000060 For example, the "hello world" application may be loaded and
61 executed on a PowerPC board with the following commands:
wdenk874ac262003-07-24 23:38:38 +000062
wdenkb8463562003-07-26 08:08:08 +000063 => tftp 0x40000 hello_world.bin
wdenk874ac262003-07-24 23:38:38 +000064 => go 0x40004
65
wdenkb8463562003-07-26 08:08:08 +0000665. To export some additional function foobar(), the following steps
67 should be undertaken:
wdenk874ac262003-07-24 23:38:38 +000068
wdenkb8463562003-07-26 08:08:08 +000069 - Append the following line at the end of the include/_exports.h
70 file:
wdenk874ac262003-07-24 23:38:38 +000071
wdenkb8463562003-07-26 08:08:08 +000072 EXPORT_FUNC(foobar)
wdenk874ac262003-07-24 23:38:38 +000073
wdenkb8463562003-07-26 08:08:08 +000074 - Add the prototype for this function to the include/exports.h
75 file:
wdenk874ac262003-07-24 23:38:38 +000076
wdenkb8463562003-07-26 08:08:08 +000077 void foobar(void);
wdenk874ac262003-07-24 23:38:38 +000078
wdenkb8463562003-07-26 08:08:08 +000079 - Add the initialization of the jump table slot wherever
80 appropriate (most likely, to the jumptable_init() function):
wdenk874ac262003-07-24 23:38:38 +000081
wdenkb8463562003-07-26 08:08:08 +000082 gd->jt[XF_foobar] = foobar;
wdenk874ac262003-07-24 23:38:38 +000083
wdenkb8463562003-07-26 08:08:08 +000084 - Increase the XF_VERSION value by one in the include/exports.h
85 file
wdenk874ac262003-07-24 23:38:38 +000086
wdenkb8463562003-07-26 08:08:08 +0000876. The code for exporting the U-Boot functions to applications is
88 mostly machine-independent. The only places written in assembly
89 language are stub functions that perform the jump through the jump
90 table. That said, to port this code to a new architecture, the
91 only thing to be provided is the code in the examples/stubs.c
92 file. If this architecture, however, uses some uncommon method of
93 passing the 'global_data' pointer (like x86 does), one should add
94 the respective code to the app_startup() function in that file.
wdenk874ac262003-07-24 23:38:38 +000095
wdenkb8463562003-07-26 08:08:08 +000096 Note that these functions may only use call-clobbered registers;
97 those registers that are used to pass the function's arguments,
98 the stack contents and the return address should be left intact.