What is Firmware? Definition and Examples
When most people think about the software that runs on electronic devices, they focus on the applications, programs, and operating systems that they interact with directly. However, there is a critical layer of software that runs "beneath" all of that – the firmware. Firmware is embedded software that is programmed onto a hardware device to enable it to function and communicate with other components.
In this comprehensive guide, we‘ll cover everything you need to know about firmware. We‘ll define what firmware is, how it differs from other types of software, and why it is so important. We‘ll look at some common examples of devices that use firmware and explore how firmware works under the hood. Finally, we‘ll discuss some best practices around firmware development and security.
Defining Firmware
Firmware refers to a specific class of computer software that provides the low-level control for a device‘s specific hardware. Firmware is essentially embedded software that is programmed onto a non-volatile memory chip, typically a ROM (read-only memory), EPROM (erasable programmable read-only memory), or flash memory chip.
The key characteristic of firmware is that it is usually tied very closely to the hardware it runs on and has direct control over the hardware components. Firmware is generally device-specific and works only on the hardware it was designed for.
Some common examples of devices that contain firmware include:
- Computers (BIOS/UEFI)
- Smartphones
- Printers and scanners
- Routers and modems
- Digital cameras
- Video game consoles
- Cars
- Smart appliances
- Medical devices
One way to think about firmware is as a small, highly specialized operating system for a piece of hardware. Just like a computer operating system (like Windows or macOS) acts as an interface between the computer hardware and the software applications, firmware acts as an interface between the hardware components of an electronic device and its higher-level software.
Firmware vs Software vs Hardware
It‘s important to understand the distinction between firmware, software, and hardware:
Hardware refers to the physical components that make up an electronic device. This includes the processor, memory chips, storage drives, power supply, display, etc. Hardware is a tangible thing that you can physically touch and manipulate.
Software refers to the programs, applications, and operating systems that run on top of the hardware to accomplish tasks for the user. Software includes the code, libraries, and executables that are loaded into a device‘s memory and processed by its CPU. Software is intangible and can usually be easily updated or replaced.
Firmware exists as a separate category that lies at the intersection between hardware and software. Firmware is software that is semi-permanently placed onto a hardware device (hence the "firm" part of firmware). Unlike normal software that is loaded onto a device‘s storage drive, firmware is stored on a special memory chip that retains information even when the power is off.
Firmware is usually very low-level software that directly controls a piece of hardware. It may handle power management, hardware initialization, timing, and data flow between hardware components. The firmware provides a consistent way for higher level software to interact with the hardware, no matter the specifics of the software.
How Firmware Works
Firmware is usually stored on a device‘s non-volatile memory like ROM, EPROM, or flash memory. When the device is powered on, the processor first loads the firmware instructions from this memory before doing anything else. The firmware initializes the hardware components, sets low-level configuration options, and provides a basic interface for the hardware to communicate.
One common firmware component is a bootloader or boot firmware. This is a very small and basic piece of firmware whose job is to correctly initialize the bare essentials of a system and then look for and load additional firmware or a full operating system. On a computer, the BIOS/UEFI firmware contains a bootloader that initializes the CPU, memory controller, and storage, then looks for a more complete OS to handoff control to.
Throughout the normal operation of a device, the firmware continues running to act as a translator between the hardware and software. Firmware abstracts away the complexities of interfacing directly with the hardware and provides a consistent API for the software to use.
Take a router as an example. The router firmware initializes the radio chip, network interfaces, and LED indicators when the router is powered on. It sets configuration options retrieved from NVRAM and starts up background processes to handle things like DHCP, NAT, and VPN tunnels. The firmware then monitors for input from the physical buttons on the router as well as network traffic coming into the WAN port. As data flows through the router, the firmware decides how to handle it at a low level (e.g. what voltages to put on which pins) while presenting a high-level interface to the user accessible through a web panel.
Firmware Development
Firmware development is a specialized skill set that combines elements of electrical engineering and software development. Firmware engineers need to be comfortable working very close to the hardware, often reading datasheets and working in low-level languages.
Some common programming languages used in firmware development include:
- C
- C++
- Rust
- Assembly
- Ada
- Embedded C
In addition, many semiconductor vendors provide specialized languages and toolchains for developing on their platforms:
- Arduino (Atmel)
- Embedded Java (Java ME)
- mbed (ARM)
- XC (Microchip)
Firmware engineers rely heavily on tools like JTAG and BDM debuggers, oscilloscopes, logic analyzers, and multimeters. Since the firmware runs so close to the hardware, debugging often requires being able to probe physical pins on a circuit board. Troubleshooting a crashed device may involve using tools like a decompiler, disassembler, or hex editor to reverse engineer and inspect the binary firmware image.
Firmware code bases tend to be highly optimized for performance and size, since they run in very resource-constrained environments. A typical firmware program might only have access to kilobytes or at most a few megabytes of memory and storage. Fancy high-level abstractions and deep stacks are usually avoided in favor of tight, efficient code.
Firmware development can be quite challenging due to the need to work so closely with a specific piece of hardware. Firmware that works in the lab may fail in the field due to environmental conditions like temperature changes or electromagnetic interference. Firmware is also very difficult to update remotely, requiring either a physical connection or a very robust OTA (over-the-air) process.
Firmware Security
Securing firmware is an often overlooked but critically important part of embedded device security. Unlike software that can be updated relatively easily, firmware updates represent a greater risk to the stability and functionality of a device. A failed firmware update can leave a device unrecoverable ("bricked").
At the same time, firmware is increasingly being targeted by hackers and malicious actors. Many high-profile hacks in recent years have exploited firmware vulnerabilities:
- Stuxnet (2010): Malware that infected Windows machines but had its payload targeted at Siemens PLCs, altering their firmware to damage centrifuges
- Mirai (2016): Botnet that recruited IoT devices by exploiting default admin credentials in firmware
- ASUS ShadowHammer (2019): Supply chain attack that compromised the ASUS Live Update Utility to push malware to thousands of PCs
- Thunderspy (2020): Series of vulnerabilities found in the Intel Thunderbolt controller firmware
Best practices for firmware security include:
- Signing firmware updates with strong cryptographic keys to prevent tampering
- Using secure boot to validate firmware authenticity on startup
- Encrypting sensitive data stored in firmware
- Disabling JTAG and other debug ports before production
- Providing a secure mechanism for automated firmware updates
- Regularly scanning for and patching vulnerabilities in firmware components, like bootloaders, TPMs, TCMs, etc.
Analyzing firmware binaries for vulnerabilities is a complex task. Some popular tools used in the firmware security community include:
- Binwalk: Multipurpose tool for analyzing and extracting firmware images
- Firmadyne: Platform for emulation and dynamic analysis of Linux-based firmware
- Ghidra: Software reverse engineering tool developed by the NSA
- CHIPSEC: Framework for analyzing the security of PC firmware platforms
Firmware by the Numbers
The explosion of connected smart devices, also known as the Internet of Things (IoT), has led to a vast increase in the amount of firmware in the world. Consider these statistics:
- There are projected to be over 75 billion IoT devices by 2025 (Statista)
- Firmware is often the most expensive software to develop, at $15-50 per line of code (arxiv.org)
- Firmware engineers in the US earn an average salary of $107,698 per year (Glassdoor)
- Embedded software (including firmware) accounts for over 50% of the codebase in IoT and IIoT devices (TheNewStack)
A Closer Look at Router Firmware
To help solidify our understanding of firmware, let‘s take a closer look at a specific type of firmware found in a very common device – a wireless router.
Router firmware usually consists of a Linux-based operating system like OpenWrt or DD-WRT along with drivers for the specific router hardware and tools for network management. When the router first powers on, a bootloader like U-Boot initializes the CPU and memory, then looks for and loads the full router firmware from NAND storage into RAM.
The firmware then initializes all the hardware-specific components like the Ethernet ports, radio antennas, and status LEDs. It may read configuration data stored in NVRAM to customize settings like the network name, admin password, port forwarding rules, etc.
The router firmware runs a series of background services to handle the core networking functions:
- DHCP client and server to assign IP addresses
- DNS proxy to handle name resolution
- Firewall to filter traffic based on IP tables rules
- NAT to map many local IPs to one external IP
- QoS to prioritize certain types of traffic
- Access point controller to manage Wi-Fi connections
- VPN server to securely tunnel traffic
Managing all these services requires very precise timing and coordination, all handled by the firmware. The firmware abstracts away the low-level details of routing packets and allows the user to control the router through a simple web interface.
Router firmware has been the source of many security vulnerabilities over the years. In 2014, a flaw was discovered in the firmware of over 12 million SOHO routers that could allow an attacker to execute arbitrary code. A 2020 report by the Fraunhofer Institute found that outdated Linux kernel versions in embedded devices like routers expose millions of devices to potential compromise.
Choosing a router with open source firmware like OpenWrt or DD-WRT can improve security through better transparency and patching. However, the best practice is to regularly check for firmware updates from the manufacturer and install them as soon as possible.
Conclusion
Firmware may be the most important type of software that most people have never heard of. It is the foundational layer upon which our digital world is built, powering everything from kitchen appliances to the electrical grid. As embedded systems continue to proliferate, firmware will only grow in importance.
For technical professionals, a solid grasp of firmware is invaluable. Embedded developers, hardware engineers, and IoT architects all need to understand how firmware fits into their products. Cybersecurity analysts and penetration testers must be familiar with common firmware vulnerabilities and attack vectors. Even web developers can benefit from knowing how firmware may impact the behavior of smart devices that interact with their applications.
At its core, firmware demonstrates the complex interplay between hardware and software in modern computing. It blurs the line between the physical and the digital, breathing life into inert silicon. So the next time you use virtually any electronic device, take a moment to appreciate the intricate dance of electrons orchestrated by the unsung hero that is firmware.