1*27b207fdSwdenkDesign Notes on Exporting U-Boot Functions to Standalone Applications: 2*27b207fdSwdenk====================================================================== 3*27b207fdSwdenk 4*27b207fdSwdenk1. Add a field to the global_data structure, the pointer to a jump 5*27b207fdSwdenk table. 6*27b207fdSwdenk 7*27b207fdSwdenk2. Jump table itself is allocated and filled in the same way as the 8*27b207fdSwdenk syscall table is (allocated with malloc() after the code has been 9*27b207fdSwdenk relocated to RAM); a special function, fixed to the table element 10*27b207fdSwdenk number 0, will be added which returns the ABI version so 11*27b207fdSwdenk applications can check for compatibility issues. 12*27b207fdSwdenk 13*27b207fdSwdenk3. It is application's responsibility to check the ABI version and 14*27b207fdSwdenk act accordingly. 15*27b207fdSwdenk 16*27b207fdSwdenk4. Pointer to the global_data is passed to the application in the 17*27b207fdSwdenk dedicated register that is used in the U-Boot to hold this 18*27b207fdSwdenk pointer. This assumes that the application is built with the same 19*27b207fdSwdenk register- allocation flags as the U-Boot itself. (Actually, this 20*27b207fdSwdenk is a requirement even now, as the 'go' command does not perform 21*27b207fdSwdenk any actions to protect this register against being clobbered by 22*27b207fdSwdenk the application). 23*27b207fdSwdenk 24*27b207fdSwdenk This approach won't work on the x86 architecture. See below. 25*27b207fdSwdenk 26*27b207fdSwdenk5. Application now calls standard library functions like printf() 27*27b207fdSwdenk instead of specially prefixed names like mon_printf() as it did 28*27b207fdSwdenk before. Present implementation of these functions (using the 29*27b207fdSwdenk system calls mechanism) will be replaced with jump stubs. 30*27b207fdSwdenk 31*27b207fdSwdenk6. To export additional functions, the following steps will have to be 32*27b207fdSwdenk taken: 33*27b207fdSwdenk 34*27b207fdSwdenk - Add the xxx() U-Boot function to the EXPORT_FUNC list 35*27b207fdSwdenk - Add initialization of the appropriate slot in the jump table 36*27b207fdSwdenk 37*27b207fdSwdenk7. To port to a new architecture, the appropriate stub code should be 38*27b207fdSwdenk provided. No other machine-dependent code is used. Once the stub 39*27b207fdSwdenk template is available, no additional coding is needed when 40*27b207fdSwdenk exporting new U-Boot functions. A pre-processor macro will be used 41*27b207fdSwdenk to automatically instantiate the stub definition for each exported 42*27b207fdSwdenk function. 43*27b207fdSwdenk 44*27b207fdSwdenkNote the following: 45*27b207fdSwdenk 46*27b207fdSwdenk- This approach uses a jump table with fixed slot allocation. That 47*27b207fdSwdenk said, to retain the ABI compatibility, no table reordering, 48*27b207fdSwdenk inserting new functions in the middle of the list or deleting 49*27b207fdSwdenk functions from the list is allowed. Any such action will break the 50*27b207fdSwdenk ABI compatibility. 51*27b207fdSwdenk 52*27b207fdSwdenk- The x86 architecture does not use a dedicated register to store the 53*27b207fdSwdenk pointer to the global_data structure. There are the following 54*27b207fdSwdenk approaches available: 55*27b207fdSwdenk 56*27b207fdSwdenk * Pass the global_data pointer to the application in a register or 57*27b207fdSwdenk as an additional argument. This requires special machine- 58*27b207fdSwdenk dependent startup code to be compiled into the application. 59*27b207fdSwdenk 60*27b207fdSwdenk * Make the x86 consistent with the rest of architectures and use a 61*27b207fdSwdenk dedicated register. This renders one register unusable in the 62*27b207fdSwdenk rest of the U-Boot code and thus increases the size of the U-Boot 63*27b207fdSwdenk binary and decreases it performance. 64*27b207fdSwdenk 65*27b207fdSwdenkThe following changes will be made: 66*27b207fdSwdenk 67*27b207fdSwdenk- The syscall handling code will be removed. 68*27b207fdSwdenk 69*27b207fdSwdenk- The include/_exports.h file will be introduced, containing the list 70*27b207fdSwdenk of the exported functions in the following form: 71*27b207fdSwdenk 72*27b207fdSwdenk EXPORT_FUNC(getc) 73*27b207fdSwdenk EXPORT_FUNC(tstc) 74*27b207fdSwdenk ... 75*27b207fdSwdenk 76*27b207fdSwdenk This list will be used to assign the slot numbers in the jump 77*27b207fdSwdenk table, to determine the size of the jump table and to generate the 78*27b207fdSwdenk code for the stub functions. 79*27b207fdSwdenk 80*27b207fdSwdenk- The include/exports.h file will be introduced, containing the 81*27b207fdSwdenk prototypes of the exported functions and the assigned slot numbers. 82*27b207fdSwdenk 83*27b207fdSwdenk- The examples/stubs.c file will be introduced, containing the code 84*27b207fdSwdenk for the jump stubs for each of the exported functions. 85*27b207fdSwdenk 86*27b207fdSwdenkImplementation Notes on Exporting U-Boot Functions: 87*27b207fdSwdenk=================================================== 88*27b207fdSwdenk 89*27b207fdSwdenk1. The patch was applied against TOT as of 7/24 12:50 MEST; the 90*27b207fdSwdenk resulting images were tested on the following boards: 91*27b207fdSwdenk 92*27b207fdSwdenk * lwmon (PowerPC) 93*27b207fdSwdenk * trab (ARM) 94*27b207fdSwdenk * inca (MIPS) 95*27b207fdSwdenk 96*27b207fdSwdenk The hello_world application was loaded and executed then: 97*27b207fdSwdenk 98*27b207fdSwdenk [lwmon] 99*27b207fdSwdenk => tftp 0x40000 /tftpboot/LWMON/hello_world.bin-avn 100*27b207fdSwdenk => go 0x40004 101*27b207fdSwdenk 102*27b207fdSwdenk [trab] 103*27b207fdSwdenk TRAB # tftp 0xc100000 /tftpboot/TRAB/hello_world.bin-avn 104*27b207fdSwdenk TRAB # go 0xc100000 105*27b207fdSwdenk 106*27b207fdSwdenk [inca] 107*27b207fdSwdenk INCA-IP # tftp 0x80200000 /tftpboot/INCA/hello_world.bin-avn 108*27b207fdSwdenk INCA-IP # go 0x80200000 109*27b207fdSwdenk 110*27b207fdSwdenk2. As neither of supported x86 boards can be built from the TOT 111*27b207fdSwdenk sources currently, the patch build was verified by manually 112*27b207fdSwdenk running the following command in the U-Boot top directory: 113*27b207fdSwdenk 114*27b207fdSwdenk > make -C examples TOPDIR=`pwd` ARCH=i386 CROSS_COMPILE= 115*27b207fdSwdenk 116*27b207fdSwdenk The rest of the code is mostly machine-independent and was not 117*27b207fdSwdenk verified. 118*27b207fdSwdenk 119*27b207fdSwdenk3. To test the x86 assembly code, a small standalone application was 120*27b207fdSwdenk written. It was built and run on the RedHat Linux 8.0 (x86). The 121*27b207fdSwdenk application performs a jump using a pointer to jump table and a 122*27b207fdSwdenk function's index in it. 123*27b207fdSwdenk 124*27b207fdSwdenk4. For the MIPS architecture, the linker script is also provided for 125*27b207fdSwdenk linking applications. The default linker script places the .text 126*27b207fdSwdenk and .data sections too far from each other so that the resulting 127*27b207fdSwdenk .bin files span about 256Mb in size. 128*27b207fdSwdenk 129*27b207fdSwdenk5. Several example applications required updating for the new API. 130*27b207fdSwdenk These applications relied upon the bd_t pointer being passed as 131*27b207fdSwdenk the 1st argument to the main function; this had changed when the 132*27b207fdSwdenk system calls were introduced, but apparently, these applications 133*27b207fdSwdenk weren't fixed at that moment. This is fixed now. 134*27b207fdSwdenk 135*27b207fdSwdenk6. GCC issues warnings for the 'sched' application. Since now the 136*27b207fdSwdenk mon_printf() function is renamed to printf(), GCC applies its 137*27b207fdSwdenk knowledge of the format specifiers to check the arguments, 138*27b207fdSwdenk complaining about ints passed as longs and vice versa. This is not 139*27b207fdSwdenk fixed yet. 140*27b207fdSwdenk 141*27b207fdSwdenk7. Only the hello_world example application was modified to make use 142*27b207fdSwdenk of the newly supplied get_version() function. The application now 143*27b207fdSwdenk prints two ABI versions, the one that the application was compiled 144*27b207fdSwdenk for and the other, actual ABI version. 145*27b207fdSwdenk 146*27b207fdSwdenk8. The following new files were added: 147*27b207fdSwdenk common/exports.c 148*27b207fdSwdenk examples/mips.lds 149*27b207fdSwdenk examples/stubs.c 150*27b207fdSwdenk include/_exports.h 151*27b207fdSwdenk include/exports.h 152*27b207fdSwdenk doc/README.standalone 153*27b207fdSwdenk 154*27b207fdSwdenk The following files are no longer used and will be removed: 155*27b207fdSwdenk examples/syscall.S 156*27b207fdSwdenk include/syscall.h 157