krishworkstech.com

What Is QEMU in Embedded Systems?

  • QEMU (Quick Emulator) is an open-source machine emulator, Linux Emulation Environment and virtualizer that enables the execution of operating systems and applications built for one hardware architecture on a different architecture.
  • It is widely used in embedded systems development to simulate target hardware platforms, such as ARM-based boards, eliminating the need for physical hardware during early-stage development, testing, and debugging.
Rectangle 26832 (1)

How to Install crosstool-NG for ARM Toolchains

Crosstool-NG is an open-source tool that helps automate the process of building cross-compilation toolchains. Originally based on Dan Kegel’s crosstool, it has evolved into a powerful, menu-driven utility. It allows you to create custom toolchains for different architectures, making it ideal for embedded development. The process typically involves steps like crosstool-ng download to fetch the required toolchain components and crosstool-ng install to build and install the complete toolchain.

image (20)
image (21)

Build a Cross-Compiler Toolchain for QEMU

  1. To emulate an ARM926EJ-S processor (ARMv5TE) on QEMU, we need a matching cross-compilation toolchain. Build crosstool NG; this makes it easy. Although there’s no exact sample for this CPU, we can start with a generic ARM target and customize it. This toolchain will allow you to build and test ARM software on your host machine using QEMU system emulation, a feature of QEMU for Linux that enables full system-level simulation of ARM platforms.
image (22)
image (23)

the build will take about half an hour. The toolchain will be installed in ~/x-tools/arm-unknown-linux-gnueabi

Anatomy of a Toolchain

After building crosstools-ng in toolchain, it’s important to understand its structure and how to use it.
The generated toolchain includes a cross-compiler and related tools located in a dedicated directory, which must be added to your system’s PATH to compile code for your target architecture.

Target: QEMU
Toolchain Prefix: arm-unknown-linux-gnueabi-
Toolchain Path: ~/x-tools/arm-unknown-linux-gnueabi/bin

Group 1707478171

In the next part, we’ll see how to use this toolchain with a practical example targeting the QEMU-emulated ARM platform.

Building complex IoT systems?

Accelerate testing and deployment with our QEMU-integrated toolchain expertise.

Verify Your ARM Cross-Compiler Setup

We previously saw how to setup cross compile environment. This command outputs the version of the cross-compiler, ensuring you’re using the correct version for your build.

image (24)

Additionally, to check the sysroot used by your cross-compiler, you can run arm-unknown-linux-gnueabi-gcc -print-sysroot. This command returns the path to the sysroot, which contains essential libraries and headers for the target architecture. The sysroot ensures that the correct dependencies are available during compilation, allowing your code to be built for the ARM target system.

Cross-Compile and Run ARM Programs with QEMU

Step 1: Write a Simple C Program (helloworld.c)
Create a new file named helloworld.c with the following content:

image (25)

Additionally, to check the sysroot used by your cross-compiler, you can run arm-unknown-linux-gnueabi-gcc -print-sysroot. This command returns the path to the sysroot, which contains essential libraries and headers for the target architecture. The sysroot ensures that the correct dependencies are available during compilation, allowing your code to be built for the ARM target system.

 

Just for reminder: C is portable at the source code level, but the compiled binary is architecture-specific.

Step 2: Compile the Program Using the Cross-Compiler
Once you’ve written the program, you need to compile it for the target architecture. Assuming you’ve already set up the ARM cross-compiler, use this command to compile the program for an ARM-based system (e.g., ARM Cortex-A8)

image (26)

arm-unknown-linux-gnueabi-gcc: Specifies the ARM cross-compiler.
helloworld.c: The source file we want to compile.
-o helloworld: Specifies the output file name (helloworld).

Step 3: Verify the Binary
After compiling the program, you can verify that the binary is correctly built for the ARM architecture using the file command.

image (27)

This confirms that the helloworld binary is an ARM-specific executable (not an x86 or other architecture binary). You can now run this on an ARM device or emulated environment like QEMU.

Step 4: Running ARM Binary using QEMU
Run the Cross-Compiled Binary with QEMU

image (28)

After running qemu-arm ./helloworld, QEMU emulates an ARM environment and executes the binary as if it were running on a real ARM device. This helps test and verify ARM programs directly on your system without needing physical ARM hardware. However, if the ARM binary dynamically links to shared libraries, QEMU needs to know where to find the ARM-compatible versions of those libraries. The -L option specifies the sysroot—a directory that mimics the root filesystem of the target ARM system and contains the required shared libraries. By passing the sysroot path using -L, QEMU can correctly load these libraries, enabling the ARM binary to run properly on your host machine.

Group 1707478165 (1)

Toolchains in Different Devices

image (19)

QEMU Toolchain Setup

Rectangle 26838

BeagleBone-Toolchains Setup

Rectangle 26839

Raspberry Pi Toolchain Setup

FAQs

QEMU (Quick Emulator) is an open-source virtualization tool used to emulate hardware platforms like ARM, enabling software development and testing without physical devices. It’s widely used in embedded systems for debugging, testing, and running cross-compiled code.

To use QEMU to run ARM binaries, install QEMU and use qemu-arm along with the -L flag to point to your sysroot. This emulates an ARM environment on your host system, allowing you to test embedded software without hardware.

QEMU is used to test toolchains by running cross-compiled binaries in a simulated target environment (e.g., ARM). This helps validate your compiler setup, libraries, and program output before deploying to physical hardware.

Scroll to Top
  • Schematic design
  • PCB and schematic source files
  • Assembling drawing files
  • Providing prototype/sample and production PCB service
  • Testing and validation of designed hardware
  • HIPAA
  • Azure Key
  • Management
  • ES, Checksum,
  • MD5sum
  • AWS
  • Azure
  • GCP
  • DigitalOcean
  • Kotlin
  • Python
  • Tensorflow
  • Computer Vision
  • ECG
  • SPO2
  • Heart Rate
  • Glucometer
  • Blood Pressure
  • UX UI Process
  • Figma and FigJam
  • Adobe Suite
  • Selenium Java
  • Postman
  • Swagger
  • Jmeter
  • SQL
  • Java Scripter
  • Test ng
  • Extents Reports
  • Flutter
  • Java
  • Kotlin
  • Swift
  • Dart
  • React JS
  • Python
  • NodeJS
  • Django
  • HTML, CSS, JS
RDBMS
  • PostgreSQL
  • Oracle
  • MySQL
  • MariaDB
No SQL Based
  • MongoDB
  • GCP
  • FirestoreDB
  • DynamoDB
  • Azure
  • CosmosDB
  • AWS