What is Firmware? Inside Firmware Development [Guide]

Share:

Inside Firmware Development: The Unsung Hero of Devices

Firmware is the secret sauce that brings electronics to life.

This guide demystifies firmware development, explains why it’s critical for devices, and provides an inside look at processes, best practices, and trends.

Key Takeaways [TL;DR]:

  • Firmware is specialised software that manages hardware and enables electronic devices to function properly.
  • This behind-the-scenes technology is the hidden hero inside our devices, from mobile phones and tablets to PCs and pacemakers.
  • We explain what exactly firmware is and why it is so important for electronics:
    • It initialises a hardware device upon startup
    • It abstracts low-level hardware details
    • It controls power management, charging, real-time I/O
    • It provides security against vulnerabilities, malware attacks and cyber hackers
    • It enables remote diagnostics, security updates and management
  • We provide an inside look at typical firmware development processes:
    • Requirements analysis, architecture design
    • Coding standards, unit testing, integration testing
    • Hardware integration, system testing, regression testing
  • Best practices for robust firmware like modular design, input validation, and static analysis
  • Challenges such as real-time demands, concurrency, and optimisation complexity
  • Exciting firmware trends including connected IoT (Internet of Things), AI integration, formal verification
  • How firmware will continue to evolve alongside cutting-edge electronics

We live in a world surrounded by electronic devices, from smartphones, mobile devices and smartwatches to game consoles, TVs, other home appliances such as coffee makers – and even lightbulbs.

But what makes these devices actually work?

Behind the sleek user interfaces and clever features lies firmware – the specialised software that controls the device hardware. 

Though often invisible to end-users, firmware is the hidden hero that brings our devices to life.

In this article, you’ll discover what firmware is, why it’s important, how it works, and get an insider’s view into firmware development processes and best practices.

What is firmware and how does it differ from software?

Firmware is a type of software that manages hardware components and allows devices to function properly.

It provides a low-level control program for a device’s specific hardware. Unlike application software, firmware runs on the device itself rather than the operating system. 

Generally, firmware is stored in non-volatile memory, such as flash memory or ROM chips, which allows the firmware to persist even when the device is powered off.

On startup, the firmware boots up and initialises the device’s hardware components.

It acts as the middleman between a device’s hardware and software. 

Why is firmware important?

Firmware plays an essential role in electronic products. Here are some of its key responsibilities: 

  • Initialise hardware: Upon startup, firmware performs initialisation routines for processors, memory, I/O interfaces and other hardware components. This brings the device into a known working state.
  • Hardware abstraction: Firmware abstracts low-level hardware details into a simpler interface for higher-level software. This hides hardware complexity.
  • Power management: Firmware handles power-saving modes, voltage regulation, and battery charging. This optimises power consumption.
  • Real-time control: Firmware provides real-time control over time-critical I/O devices like sensors, motors, and RF chips. This enables real-time response.
  • Safety and security: By controlling hardware access, firmware provides security against malicious attacks. It also implements safety checks for fault conditions.
  • Diagnostics and updates: Firmware supports methods for field diagnostics and bootloaders for firmware updates and remote management. This allows devices to be maintained after deployment.

 

Without firmware, devices would be bricks! It enables even the most sophisticated hardware capabilities.

Security measures such as software updates help guard against hackers and other security risks

How does firmware work?

Firmware architecture varies across devices but typically consists of a bootloader, OS kernel, device drivers, middleware, and application code. 

Here is a high-level overview:

  • Bootloader: This immutable code runs first when a device powers on. It initialises core hardware like the CPU and memory, then loads the main firmware image from storage.
  • OS kernel: The kernel manages system resources and provides core services like multitasking and memory allocation. For small devices, it may be a real-time operating system (RTOS).
  • Device drivers: these enable the OS to communicate with hardware like radios, sensors, and storage. They abstract the hardware complexity into a common interface.
  • Middleware: Middleware provides connectivity, security, protocol stacks, and other services above the OS. For example, a TCP/IP stack for network connectivity.
  • Application code: The main application firmware implements the device’s end-user functionality – for example, user interfaces, algorithms, and network protocols.

Architecture Diagram

Diagram of firmware architecture

During operation, firmware remains in the device’s memory and responds to events like user input, sensor data, or external messages.

Based on these stimuli, it controls the hardware appropriately to perform specific tasks.

Inside Firmware Development Processes

Developing quality firmware requires hardware-software co-design, where the firmware and hardware are designed in tandem.

Here’s an overview of typical firmware development workflows:

9-Step Embedded System Firmware Development Workflow

Requirements are defined, covering functionality, performance, safety, and other metrics. These guide the design.

The firmware architecture is designed to include task breakdown, modules, memory maps, stack sizes, and APIs.

Firmware code is written in languages like C/C++ or Rust. Strict coding standards are followed.

Individual modules are tested to verify functionality and robustness. Test suites exercise code paths and validate inputs/outputs.

Modules are integrated incrementally while testing that the interfaces work correctly. Hardware dependencies are stubbed out.

The code is ported to real hardware and fine-tuned. Hardware interfaces are verified, and performance is optimised.

The fully integrated stack is validated to meet all requirements. Power, security, reliability, and use cases are thoroughly tested.

Existing functionality is re-tested after any changes to ensure no new bugs are introduced. Test suites are continuously expanded.

In-depth documentation covers requirements, design, APIs, toolchains, testing, and other technical intricacies.

Configuration management and revision control systems track changes and releases. Automated testing and continuous integration practices are adopted to catch issues early.

Development Best Practices

Here are some firmware best practices for development teams:

  • Modular architecture: Logically separate functionality into modules with well-defined interfaces. This improves testability and reusability.
  • Hardware abstraction: Isolate hardware dependencies into a separate layer to avoid mixing hardware and application logic.
  • Input validation: Check and sanitise all inputs from external sources like sensors before use. This prevents buffer overflows and crashes.
  • Limited complexity: Stick to a single core responsibility for each module and minimise statefulness. Complex code is buggy code.
  • Static analysis: Leverage static analysis tools to detect bugs like null pointers, race conditions, and memory leaks during compilation.
  • Dynamic analysis: Perform dynamic analysis like memory profiling and logic analysers during runtime to identify bottlenecks.
  • Fail-safe defaults: The system should fail gracefully to a safe state if invalid data is encountered. Safety is the top priority.
  • Autonomous self-validation: Continuously validate the system state with watchdog timers, assertion checks, and reasonableness tests.
  • OTA [Over-the-air] updates: Design firmware to support remote updates via standard management protocols. This enables field upgrades.
  • Debugging access: Provide debugging and trace ports for gaining visibility into field failures. Debugging should be possible at both hardware and software levels.
  • Rugged design: Harden firmware against random faults, noisy inputs, timing violations, and resource exhaustion. Assume the worst and design for it.

By following best practices, firms can develop custom firmware that is robust, secure, and easily maintainable. This results in resilient products.

Development Challenges

Firmware development comes with its own unique challenges, including:

  • Constrained resources: Microcontrollers have limited memory and processing power. Firmware needs to be compact and efficient.
  • Real-time demands: Meeting timing deadlines for time-sensitive operations like motor control requires real-time capabilities.
  • Concurrency: Firmware often needs to juggle multiple tasks like responding to inputs, updating displays, and background monitoring.
  • Fault tolerance: Bugs can cause systems to crash or become unresponsive. Firmware must be robust and fault-tolerant.
  • Low-level optimisation: Achieving the highest efficiency requires optimising at the assembly level in addition to C/C++ optimisations.
  • Limited visibility: Lack of complete system visibility during integration testing makes bugs hard to trace. Hardware debugging skills become critical.
  • Cross-platform support: Firmware often needs to support multiple hardware variants, such as silicon revisions. Hardware variability must be handled properly.
  • Long life cycles: Products may stay in service for years. Firmware needs to be forward-compatible and maintainable long-term.
  • Safety criticality: Any glitch can have disastrous consequences. Rigorous processes are needed to assure firmware security and safety.
  • Difficult upgrades: Updating fielded devices requires fail-safe update mechanisms. Both forward and backward compatibility must be considered.
  • With so many constraints, firmware demands broad systems thinking and strong technical skills to develop correctly.

Toolchain

Firmware development requires an extensive toolchain covering activities ranging from requirements to deployment:

  • Processor IDE: A cross-platform IDE like Eclipse Embedded CDT integrates editing, compiling, debugging, and project management.
  • C/C++ compiler: A cross-compiler like GNU Arm Compiler converts firmware code into target processor instructions. Optimisation levels can be configured.
  • Debugger: A hardware debugger like JTAG enables stepped execution, breakpoints, and memory inspection on the target device.
  • Emulator: QEMU can emulate target hardware for rapid prototyping before boards are available.
  • Version control: Git or SVN enables collaborative development and maintains revision history.
  • Build automation: Makefiles and build systems automate compiling, linking, and integrity checking steps.
  • Bug tracker: JIRA or Bugzilla tracks reported issues and links them to source commits.
  • Static analysis: Tools such as Coverity scan for bugs and ensure compliance with standards like MISRA C.
  • Test framework: xUnit frameworks allow writing and managing automated test cases and generating reports.
  • Profilers: Valgrind and similar tools analyse execution times, memory usage, and call graphs for optimisation.
  • Documentation: Doxygen auto-generates documentation from source code comments.

By combining open source and commercial tools, firmware teams can maximise productivity and quality. The toolchain supports the entire development lifecycle.

Handling Defects and Recalls

Despite extensive testing, defects still occur in complex firmware. Handling them properly ensures customer safety and satisfaction:

  • Root cause analysis: Thoroughly investigate and determine the technical source of each defect. This prevents recurrences.
  • Containment: If defects pose safety risks, production may be temporarily halted pending investigation.
  • Reporting obligations: Notify regulatory bodies of potential safety issues. Be transparent with customers.
  • Mitigations: Provide workarounds like temporary patches to limit damage until permanent bug fixes are ready.
  • Corrective actions: Update specifications, development processes, tools, and testing to address systemic issues.
  • Regression testing: All related functionality must be re-tested after fixes to prevent regressions.
  • Field updates: Distribute firmware updates to fielded products to eliminate defects. Make this simple for customers.
  • Failure monitoring: Continuously monitor field performance to identify failure patterns. Analyse to guide further improvements.
  • Documentation: Meticulously document all actions taken, analyses, fixes applied, and lessons learned for each issue.

 

By diligently following quality processes, device manufacturers can continuously improve firmware robustness and avoid costly recalls.

The Future of Firmware - Trends to Look Out For

Automotive Firmware - inside a driverless vehicle
Automotive firmware is gaining prominence due to the rise of driverless vehicles

Firmware has come a long way from the simple bootstrap loaders of the 1980s. The scope, complexity, and business impact of firmware will only accelerate going forward. Here are some trends to watch:

  • Connected everything: With IoT, even basic appliances will run networked firmware stacks. Interoperability and wireless connectivity will become mandatory.
  • Artificial Intelligence: AI/ML techniques will move into firmware for locomotion, navigation, object recognition, predictive maintenance, and more.
  • Security: As attacks proliferate, security technologies such as TrustZone will become an integral part of firmware architectures. Updates must encrypt and authenticate.
  • Over-the-air updates: To avoid recalls, all firmware will support remote wireless updates using standard protocols like OMA-DM.
  • Automotive: Autonomous driving places huge demands on automotive firmware. Functional safety standards like ISO 26262 are becoming essential.
  • Rust adoption: To prevent memory bugs, Rust usage is likely to expand beyond OS kernels into application firmware.
  • Formal methods: Formal verification will complement testing to mathematically prove the absence of specific defects in critical firmware.
  • Increased scrutiny: Regulators will impose stricter oversight over firmware, especially in the healthcare and automotive verticals. Compliance becomes mandatory.
  • Consolidation: Automation and abstraction will consolidate firmware roles. Deep hardware skills may become less common outside chip vendors.

 

Exciting times are ahead! As long as electronics persist, firmware will continue to play a pivotal role in building robust and intelligent devices that enhance our lives.

Bringing Firmware to Life

We hope this guide has helped demystify firmware development. While firmware may operate behind the scenes, it is crucial to unlocking hardware capabilities and enabling the latest innovations.

At ByteSnap Design, our experts have been breathing life into electronics through robust firmware for over 16 years.

Having shipped millions of production units across consumer, medical, and industrial devices, we have accumulated extensive firmware development wisdom spanning architecture, performance, safety, and security.

Ready to tap into our firmware superpowers?

Get in touch today - we collaborate with clients at any stage - from upfront consulting to hands-on development.
Our passion is to collaborate with partners to transform product visions into reality through silicon-optimised firmware.
Anthony Wall Senior Software Engineer

Anthony is a Birmingham-based electronics and software engineer who has been creating bespoke embedded products since 2019.

While studying for his Masters in Electronics Engineering in 2018, he worked at the Aston Institute of Photonic Technologies, developing advanced laser control solutions for the in-house research teams. Since moving to ByteSnap, he has developed a wide range of products, from smartwatches and AI cameras to fluid monitoring and hydraulic control systems.

Outside of the office, Anthony enjoys creating digital art and snowboarding.

Share:

Related Posts