Use SDK everywhere



  • Kendryte's workflow rely on cmake and if you want to use some other tools, adapt projects or compile your single file program manually, you may find that setup annoying.

    In fact, what you need is two (or three if you need sdk) files for you to compile and use the SDK.

    1. crt0.o it will be the entry of your program
    2. kendryte.ld it tells linker how to link you objects
    3. libkendryte.a that's how you get all the sdk functions without compiling them every time.

    First, you need to create a project in the src folder in your SDK. It needs a main() for the compiling process to begin, but the other content is not important. Then, you compile it using cmake .... & make, you will find crt.S.obj in build\lib\CMakeFiles\kendryte.dir\bsp that's the first file you will need. Copy it to kendryte-toolchain/riscv64-unknown-elf/lib and replace the original crt0.o.

    Second, you can now remove(or move) the crt.S in ./kendryte-standalone-sdk/lib/bsp. Modify the cmake script, kendryte-standalone-sdk/cmake/compile-flags.cmake, remove -nostartfiles. Now, clean the build folder and rebuild the project. Goto build/lib and copy libkendryte.a. I'd suggest to put to ./kendryte-toolchain/riscv64-unknown-elf/lib so I can access to it everywhere, but it depends on you.

    Third, you will find kendryte.ld inside lds folder, also copy it to ./kendryte-toolchain/riscv64-unknown-elf/lib so you can access it by -T kendryte.ld everywhere.

    Now, you will be able to use the SDK, by simply (if you add toolchain to you PATH):

    riscv64-unknown-elf-gcc main.c -mcmodel=medany -lkendryte -lm -T ldscripts/kendryte.ld -static
    

    (You need to add

    void _fini(){
    
    }
    
    void _init(){
    	
    }
    

    to your source because GCC's linking order. You can also put them into crt0.o...
    )

    And get your bin by

    riscv64-unknown-elf-objcopy --output-format=binary a.out 1.bin
    

    Also, you may copy the header files to kendryte-toolchain/riscv64-unknown-elf/include/kendryte.

    If you won't use SDK, your entry would be void _init_bsp(int core_id, int number_of_cores), refer lib/bsp/entry_user.c for further info.