|
|
пре 2 месеци | |
|---|---|---|
| .github | пре 2 месеци | |
| arch | пре 1 година | |
| crt | пре 7 месеци | |
| helloworld | пре 9 месеци | |
| include | пре 2 месеци | |
| mkconfigs | пре 9 месеци | |
| src | пре 8 месеци | |
| testcases | пре 5 месеци | |
| toolchain | пре 3 месеци | |
| .gitignore | пре 5 месеци | |
| ARCH.md | пре 1 година | |
| ARCH_zh.md | пре 1 година | |
| LICENSE | пре 3 година | |
| Makefile | пре 2 месеци | |
| README.md | пре 2 месеци | |
| README_zh.md | пре 2 месеци | |
| SConscript | пре 1 година | |
| _codeql_detected_source_root | пре 2 месеци | |
| mlibc.ld | пре 6 месеци |
中文 | English
Embedded libc, a libc library adapted for embedded systems and bare metal environments.
├───arch -- Hardware-specific optimized implementations
├───crt -- Hardware-specific startup code
├───include -- Header files
│ └───sys -- System-related header files, typically included as <sys/head.h>
├───src -- Source files
│ ├───internal -- Internal header files
│ ├───misc -- Miscellaneous, contains modules that can be implemented in a single file
│ ├───stdio -- Standard IO module
│ └───stdlib -- Standard utility library module
├───helloworld -- Helloworld testcase
│ └───qemu -- qemu bare-metal config
│ └───qemu-device -- Specific to the QEMU virtual machine device, related scripts and header files
├───mkconfigs -- Scripts related to make
└───qemu -- qemu configuration
● mlibc can support multiple embedded toolchains, including gcc (arm/risc-v) and even LLVM compilers.
● Designed for low-resource systems, providing excellent support for embedded real-time operating systems (such as RT-Thread) and bare metal.
● Optimized for RISC-V 32/64, compatible with mainstream RISC-V MCUs.
● Uses make and scons for building.
● Reserve
● Use QEMU/RISC-V 32GC simulation to output the first "hello world" (completed).
● Add the basic crt.s, string, and printf functions for the bare-metal version of mlibc (completed).
● Improve mlibc based on this environment.
For simple C library compilation, the development environment is relatively straightforward; make and the appropriate toolchain are sufficient.
make + toolchain
Compile the C library
Navigate to the mlibc folder, open the command line, and use make to compile the static library.
# Here, we use the ARM architecture static library as an example
make mlibc ARCH=arm
A static library named libmlibc.a will be generated in the mlibc/build/arm directory. To integrate it with the toolchain, you can rename the file to libc.a for use.
Compile crt0
Navigate to the mlibc folder, open the command line, and use make to compile crt0.
# Here, we use the ARM architecture crt0 as an example
make crt0 ARCH=arm
The generated file will be located in mlibc/build/$(ARCH)/crtobj, named crt0.o.
Tutorial for setting up the environment on Windows:
Note: The original RT-Thread documentation link is outdated. Please refer to the official RT-Thread website (https://www.rt-thread.org/) or repository (https://github.com/RT-Thread/rt-thread) for the latest documentation on setting up the development environment.
By following the official tutorials, you can run RT-Thread in a Windows environment.
Navigate to the rt-thread\bsp\qemu-vexpress-a9 folder, open env, and enter menuconfig in the command line to enter the configuration interface.
Switch DFS v2.0 to DFS v1.0:
Download the mlibc package:
mlibc: Embedded libc, especially for RISC-VAfter finishing the menuconfig, you need to download the mlibc package before compiling:
# Load the RT-Thread environment
. ~/.env/env.sh
# Update packages to download mlibc
pkgs --update
This will download mlibc to bsp/qemu-vexpress-a9/packages/mlibc-latest.
Then you can enter scons -j12 in the command line to compile.
Note: There are known compilation issues with vexpress-a9 + RT-Thread integration. This may be due to compatibility issues with the current RT-Thread version. Please refer to the RT-Thread repository for updates.
For those unsure where to download the source code, you can refer to the official RT-Thread documentation.
Navigate to the rt-thread\bsp\stm32\stm32f407-rt-spark directory, then open env and enter menuconfig in the command line to enter the configuration interface.
Enable the file system (optional):
Enable fatfs (optional):
Download the mlibc package:
After finishing the menuconfig, you need to download the mlibc package before compiling:
# Load the RT-Thread environment
. ~/.env/env.sh
# Update packages to download mlibc
pkgs --update
This will download mlibc to the packages directory.
make + qemu + toolchain
Currently, five types of QEMU bare metal startup codes have been supported.
| QEMU Device | Hardware Architecture | Toolchain |
|---|---|---|
| vexpress-a9 | arm | arm-none-eabi-gcc |
| mps3-an536 (requires latest QEMU) | arm | arm-none-eabi-gcc |
| virt-aarch64 | aarch64 | aarch64-unknown-elf-gcc |
| virt-riscv32 | riscv32 | riscv32-unknown-elf-gcc |
| virt-riscv64 | riscv64 | riscv64-unknown-elf-gcc |
Linux: Add the following environment variables to the ~/.bashrc file through commands. Replace YOUR_PATH_TO_TOOLCHAIN with the corresponding path of your toolchain.
Note: If your toolchain path is "/opt/gcc-arm-none-eabi-10-2020-q4-major/arm-none-eabi-gcc" , then YOUR_PATH_TO_TOOLCHAIN should be "/opt/gcc-arm-none-eabi-10-2020-q4-major/arm-none-eabi-".
echo "" >> ~/.bashrc #Append a a line break to prevent content merging
echo "export MLIBC_TOOLCHAIN='YOUR_PATH_TO_TOOLCHAIN'" >> ~/.bashrc
source ~/.bashrc
Windows: Open PowerShell and replace YOUR_PATH_TO_TOOLCHAIN with the corresponding path of your toolchain.
[System.Environment]::SetEnvironmentVariable("MLIBC_TOOLCHAIN", "YOUR_PATH_TO_TOOLCHAIN", "User")
#:After the configuration is completed, you need to restart the terminal for the changes to take effect.
Navigate to the mlibc root folder and open the command line.
# Here, we use qemu-vexpress-a9 as an example
make qemu-hello QEMU_BOARD=qemu-vexpress-a9 ARCH=arm
After executing the command, an executable file named qemu-vexpress-a9.elf will be generated in the mlibc/build/arm/qemu/qemu-vexpress-a9 folder.
Run the script qemu.bat in the corresponding folder under mlibc/helloworld/qemu/{qemu-device}.
# Navigate to the qemu device folder
cd helloworld/qemu/qemu-vexpress-a9
# Enter the following command in the command line
qemu.bat
Information for each virtual environment is as follows:
| Filename | Virtual Device | Build Command |
|---|---|---|
| qemu-vexpress-a9 | vexpress-a9 | make qemu-hello QEMU_BOARD=qemu-vexpress-a9 ARCH=arm |
| qemu-mps3-an536 | mps3-an536 | make qemu-hello QEMU_BOARD=qemu-mps3-an536 ARCH=arm |
| qemu-virt-aarch64 | virt-aarch64 | make qemu-hello QEMU_BOARD=qemu-virt-aarch64 ARCH=aarch64 |
| qemu-virt-riscv32 | virt-riscv32 | make qemu-hello QEMU_BOARD=qemu-virt-riscv32 ARCH=riscv32 |
| qemu-virt-riscv64 | virt-riscv64 | make qemu-hello QEMU_BOARD=qemu-virt-riscv64 ARCH=riscv64 |
For convenience, we provide pre-built GCC toolchains with mlibc for multiple architectures. These toolchains are automatically built and released using GitHub Actions.
Visit the Releases page to download pre-built toolchains:
arm-linux-eabi_for_x86_64-pc-linux-gnu-*.tar.gzriscv32-unknown-elf_for_x86_64-pc-linux-gnu-*.tar.gzriscv64-unknown-elf_for_x86_64-pc-linux-gnu-*.tar.gzaarch64-linux-gnu_for_x86_64-pc-linux-gnu-*.tar.gz# Download and extract
tar -xzf <toolchain-tarball>.tar.gz
# Add to PATH
export PATH=/path/to/toolchain/bin:$PATH
# Verify installation
arm-linux-eabi-gcc --version
If you prefer to build the toolchains yourself:
See toolchain/README.md for detailed instructions on building with Docker.
The repository includes GitHub Actions workflows for automated builds:
For more information, see .github/workflows/README.md.
mlibc is fully open-source, following the MIT license. It allows for commercial use and modifications without any concerns, provided that the MIT license is declared in the software, with no potential commercial risks.
How to
Fork the repository
Create Feat_xxx branch
Commit your code
Create Pull Request
mlibc follows the MIT License free software license. It's completely open-source, can be used in commercial applications for free, does not require the disclosure of code, and has no potential commercial risk.It is only necessary to declare that the MIT protocol is used in the software.