简体   繁体   中英

Simplest way to execute binary (INTEL FSP) file from C/C++ program

I am trying to integrate INTEL FSP in my custom OS for silicon initialization, for this I have to build OS with FSP binary at some valid address. I have searched a lot, but can not find binary integration guide anywhere, every where they are talking about APIs and FSP integration with coreboot. Is there any simplest way by which I can call binary file from my OS which is written in C?

This git hub link solved my issue. Following is the code snippet for MACRO definition INCBIN(), which uses assembly pseudo-instruction incbin in order to embed binary fie in the executable.

#define STR2(x) #x
#define STR(x) STR2(x)

#define INCBIN(name, file) \
    __asm__(".section .rodata\n" \
        ".global incbin_" STR(name) "_start\n" \
        ".type incbin_" STR(name) "_start, @object\n" \
        ".balign 16\n" \
        "incbin_" STR(name) "_start:\n" \
        ".incbin \"" file "\"\n" \
        \
        ".global incbin_" STR(name) "_end\n" \
        ".type incbin_" STR(name) "_end, @object\n" \
        ".balign 1\n" \
        "incbin_" STR(name) "_end:\n" \
        ".byte 0\n" \
); \
extern const __attribute__((aligned(16))) void* incbin_ ## name ## _start; \
extern const void* incbin_ ## name ## _end; \

The INCBIN macro should be called globally. Following we are including "binary.bin" which will be accessed through "foobar" from the application.

INCBIN(foobar, "binary.bin");

After compiling with above code snippet, "binary.bin" should be compiled with the resulting executable. Now in order to access above binary file, "foobar" has to be used. "incbin_foobar_start" will have the starting address & "incbin_foobar_end" will have binary end address. Then the last step is to do memcpy() operation in order to place the binary file to the location (memory address) at which FSP was built.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM