- How are firmware and device driver different and related? I think both control devices?
- Is firmware always self-booting, while driver must be run/booted by OS?
Firmware is the software that runs on the device. A driver is the software that tells your operating system how to communicate with the device. Not all devices have firmware--only devices with some level of intelligence.
I'm not exactly sure what you mean... generally speaking, firmware has nothing to do with "booting"... I think maybe what you're asking is, do devices with firmware always have the firmware installed on the device, or is it loaded after boot time. If that's what you're asking, the answer is no...
Most commonly, devices with firmware have the firmware programmed into the device (either with a ROM chip, or a programmable ROM chip), but there are some devices where the firmware is loaded into the device at initialization time. I can think of some network cards and webcams that operate this way, but I'm sure there are others as well.
Firmware implements low-level details that are required to operate the hardware, and provides an API/ABI to a higher level. A device driver provides an adapter between the OS and the API/ABI exposed by the firmware.
The modern definition or common usage of firmware has nothing to do with a specific software functionality. Firmware is simply software that is stored in non-volatile semiconductor memory (e.g. PROM, EEPROM or flash) chips rather than a mass storage device such as a hard drive. The stored software could be a monolithic linked binary, or consist of loader, kernel and application modules. (OTOH I've seen some TV tuner cards for PCs that require loading of "firmware" by the Linux kernel in order to complete initialization.)
The origin of the term has to do with processor-controlled logic versus hardwired logic. Software stored on hard drives could be easily modified and updated. Revisions and updates to hardwired logic required board or module redesign and replacement. The middle ground was a processor executing software to control hardware. The software was called firmware to reflect the middle ground between software versus hardwired logic. Originally the firmware was stored in ROM, PROM or EPROM chips in order to maintain board modularity. The advancement of EEPROM and flash chips allowed in-circuit and on-board updates of the firmware.
As processors (and peripherals) got smaller and cheaper and less power hungry, the possibilities for embedding them in every kind of device/appliance expanded. In order to make the software to operate these devices rugged and secure, the software is stored in flash memory chips rather than a hard drive; it also makes the device smaller and a lot cheaper. The term firmware has been expanded to encompass all software in devices/appliances with embedded processors, even though some parts of the stored code could have no relationship to replacing hardwired logic.
Firmware is a combination of persistent memory, program code, and the data stored in it. Typical examples of devices containing Firmware are embedded systems such as traffic lights, consumer appliances, digital watches, computers, computer peripherals, mobile phones, and digital cameras. The Firmware contained in these devices provides the control program for the device.
In fact, SuperUser's
drivers tag is defined:
A driver, also called a device driver or software driver is software that allows higher-level computer programs to interact with a hardware device. When a computer program requests interaction with a certain hardware device, the driver will handle instruction and output translation between the device and the computer program invoking the driver.
firmware tag is defined:
In general, the difference between software and firmware is the level at which it interacts with the hardware. Firmware interacts at the very low level of the hardware while software interacts at high levels. Firmware generally controls the basic timing, controls and functionality of hardware.
Originally I thought that
firmware was installed onto the chip or board directly and lived there, which is why it has to be "flashed", whilst you would install a
driver on top of an operating system.
Firmware allows the hardware to "do" stuff, and
drivers allow software to interact with the hardware.
For computer platforms, microcontroller firmware implements some functionalities of hardware and provides some interfaces. UEFI firmware works with microcontroller firmware to handle the computer before OSs and its drivers kick in, initializes the hardware and provides necessary information to the OSs. Thus, the OSs can install the correct drivers and drivers know the available way to control the hardware. Drivers can invoke firmware routines or directly control the hardware to carry out tasks send by OSs. All firmware is self-contained subsystems automatically load and run when hardware switchs on , can work together to compose a bigger system. OS drivers provide interfaces for hardware/software, is part of a OS, have to loaded by OSs, can't directly run by hardware.
Firmware is a software system developed for a specific hardware platform. Its role vary significantly for different hardware platform. Let's see some examples.
On mainboards, there are one or more PCIe controllers. A PCIe controller is typically implemented as a microcontroller. A microcontroller is a small integrated circuit (IC) that contains a CPU core, memory, and various peripherals, all integrated into a single chip. These microcontrollers are designed to handle specific tasks and functions efficiently. In the case of a PCIe controller, the microcontroller is specifically tailored to manage the data transfer and communication between the Central Processing Unit (CPU) and the PCIe devices connected to the mainboard. The software system runs on these microcontrollers is firmware. Microcontroller firmware is invoked to initialize and control PCIe devices. There is a similar microcontroller and firmware with similar roles in almost all mainboard components (Network Interface Card (NIC) , Hard Drive (HDD/SSD) Controller)and peripheral devices (USB flash memory, printer).
Unified Extensible Firmware Interface (UEFI) is a specification prescribing the architecture of the firmware used by computer platforms. The CPU on a computer is hardwired to run the UEFI firmware. The UEFI firmware initializes the hardware components and loads its modules stage by stage which is called UEFI boot stages. Security Phase (SEC) is the first stage. It configures temporary RAM (often CPU cache as RAM), configures stack and heap in the temporary RAM, invokes Pre-EFI Initialization (PEI) with location and size of firmware volume (FV), temporary RAM, stack and heap. Main memory is not available yet. PEI is the second stage. It does the main memory and other early hardware initialization, also does firmware recovery operations. The third stage is Driver Execution Environment (DXE). As main memory available now, most modules are loaded and most hardware is initialized, like CPU, chipset, mainboard, and boot devices. EFI drivers or Option ROMs of PCI devices are executed. The fourth stage is Transient System Load (TSL). Here you either enter the UEFI shell or execute an UEFI application, like the Operating System (OS) boot loader. Then, the last stage Runtime (RT) comes. The loaded OS takes over the computer.
As you can see, UEFI firmware and microcontroller firmware is quite different. UEFI firmware looks like an OS, has drivers, applications and graphic user interface (GUI)/command-line interface(CLI). It invokes microcontroller firmware to control other devices. Contrast to that, microcontroller firmware is way simpler, without GUI/CLI, only responsible for one component or peripheral device.
The software systems used by video game consoles (PlayStation, Xbox), routers, switches, kiosks, and many embeded systems used in vehicles, appliances, robots and Internet of Things (IoT) devices are frimware too. Like the UEFI firmware, some of them have similar features with an OS, like user applications, system applications, kernel, drivers, boot loaders. It is not very clear in some cases if it is an OS or firmware. But they are all designed for a specific hardware platform with relatively specific purposes. While OSs are more general, run on a variety of hardware platforms and can do all the things the above devices do.
A driver is a software system developed to provide interfaces of hardware/software which are invoked by other software systems. It can has a layered architecture. Driver stack refer to a hierarchical arrangement of multiple drivers that work together to enable the communication between a hardware device and the OS or software applications. Each layer in the driver stack is responsible for specific tasks, and the interaction between the layers allows for efficient handling of hardware functionality and data flow. Layered drivers are common in modern operating systems to provide modularity, flexibility, and support for a wide range of hardware devices. It is obviouly that drivers have to correctly communicate with the hardware/software which it provides interfaces, and the software which invokes the interfaces.