Newlib: The ‘Accelerator’ for Embedded Development

Introducing a project known as the “C Library Magic Tool” in the embedded community—Newlib. Whether you are a novice in chip development or an expert in low-level programming, Newlib can help you quickly handle the C standard library, mathematical operations, I/O interfaces, and more, making embedded system development easier.

Newlib: The 'Accelerator' for Embedded Development

What is Newlib? Newlib is a collection of C libraries tailored for embedded platforms by the GNU project, covering almost all C89 and C99 standard functions, as well as commonly used components like POSIX I/O, file systems, and mathematical libraries. It was initiated by Red Hat engineer Rich Felker, derived from the Sourceware newlib-cygwin repository, and is maintained by bminor as a daily updated mirror.

Why Choose Newlib?

  • • Lightweight: Compared to glibc, Newlib focuses on embedded systems without unnecessary features, making it easy to trim down.
  • • Cross-platform: Supports various architectures including ARM, MIPS, PowerPC, and RISC-V.
  • • Portable: Provides flexible “syscalls” hooks for easy integration with low-level drivers.
  • • Active community: Daily updates with hundreds of contributors regularly maintaining it, ensuring quick bug fixes and feature iterations.

Core Components of Newlib

  • newlib: Implementation of the C standard library, including string handling, memory management, formatted I/O, etc.
  • libgloss: Hardware Abstraction Layer (HAL) that implements system calls for interfacing with underlying hardware.
  • winsup: Windows support layer that allows building a Cygwin-compatible environment on Windows.
  • libc and libm: Provide the standard library and mathematical library, covering functions like sin, cos, sqrt, printf, malloc, etc.

How to Get Started?

  1. 1. Clone the repository:
    git clone https://github.com/bminor/newlib.git
  2. 2. Configure the build:
    cd newlib
    ./configure --target=arm-none-eabi --prefix=/opt/newlib
    make all
    make install
  3. 3. Integrate into your cross-compilation toolchain: Add <span>/opt/newlib/lib</span> and <span>/opt/newlib/include</span> to your toolchain.

Usage Tips

  • • Adjust <span>syscalls.c</span>: Implement functions like <span>/_write()/_sbrk()</span> based on your bare-metal drivers to connect printf, malloc, etc., to UART/SD card.
  • • Customize components: If you only need libc and libm, you can add parameters like <span>--disable-newlib-io-long-long</span> during <span>configure</span> to further reduce size.
  • • Familiarize with multilib: Supports multiple floating-point ABIs and hardware floating-point; <span>make MULTILIB_DIRS=...</span> can handle both soft and hard float versions at once.

Conclusion Newlib, as a powerful C library tool for embedded systems, is known for its lightweight, customizable, and highly portable nature. Whether you are doing bare-metal development or working with an RTOS, you can easily get started. Want to make your firmware smaller, faster, and more reliable? Try Newlib and experience the efficiency leap brought by community empowerment!

Project Address: https://github.com/bminor/newlib

Leave a Comment