tools For the development of embedded firmware, you need tools to convert the human-readable program into machine code that the computer chip can execute. The Kendryte K210 computer chip has a RISC-V central processing unit (CPU). The CPU can read and execute machine code instruction from the RISC-V instruction set.

The Berkely University of California developed the RISC-V instruction set together with a set of tools named the RISC-V GNU toolchain. An appropriate tool is used to do a specific task. An overview of the most used tools follows in this blog.

RISC-V GNU toolchain

The most common tools used for bare-metal programming are: tools

  • assembler
  • compiler
  • archiver
  • linker
  • objcopy
  • objdump

Software tools represented as text under the arrows in the schematic.

Assembler

tools You use the assembler to write programs using the instructions from the computer chip in our case the RISC-V instruction set. An assembly language program consists of abbreviations of the instructions. We call these abbreviations mnemonics. The assembler transforms the assembly language mnemonics in a binary file known as an object file.

By convention, an assembly language filename ends with .s. The output of the assembler, an object file ends with .o.

Compiler

tools Writing computer programs in assembly language is not easy. For this reason, computer scientist created other programming languages. These are programming languages like C and C++. The compiler translates the C or C++ source code into machine code instructions. Like the assembler, the compiler stores the result in an object file. By convention, a filename for a C program ends with .c and a C++ filename ends with .cpp. The C/C++ programming language uses header files to declare the functions in the C/C++ files. The filenames of header files end with .h or .hpp.

Archiver

tools Instead of sharing a list of source files or object files it is common to bundle object files together in an archive file. These archive files are used to create function libraries. It saves time because the user of the library does not need to recompile the source code. One or more header files contain the declaration of the functions in the library.

By convention, an archive filename ends with .a.

Linker

tools The linker combines the separate object files and archive files (libraries) into a binary file. The output file is in the Executable and Linkable Format (ELF). By convention, this file has the .elf extension. For bare-metal RISC-V programming this file is a file according to the RISC-V calling convention. The location of memory and peripherals is different for every RISC-V processor. A linker script defines how the memory layout of a computer chip looks. By convention, the filename of the linker script ends with .ld.

objcopy

tools Most computer chips can’t read the Executable and Linkable Format directly. With the objcopy tool we convert the ELF file into a file format we can program into the chip. File formats for computer chip programming are commonly in the binary or text-based Intel hex file format. By convention, the filename of a binary Intel hex file ends with the .bin extension and the text version ends with .hex extension.

objdump

tools There are some occasions where you need to look at the generated machine code. The GNU toolchain has a tool that reads the binary file and puts is in a human-readable text format. By convention, the filename of this listing file ends with .lst.

Visual Studio Code extension

I made a Visual Studio Code extension you can download at my Github.