4

Does firmware of a device run in the device or the device's controller?

When does firmware of a device run? Does it run if and only if the cpu sends commands and/or data to the device's controller?

For example,

  • for a hard drive and its controller and firmware, does its firmware run in its controller and if and only if the cpu reads/writes to the hard drive?

  • for a wireless adapter and its firmware, does its firmware run if and only if the computer is connecting or connected to the wireless internet?

  • for BIOS, is it firmware for the bare computer system. Does it run in the cpu? Does it still run after the OS fully started?

Thanks.

I don't think the linked question is about firmware.

Tim
  • 5,405
  • 7
  • 48
  • 84
  • 1
    possible duplicate of [How Do Computers Work?](http://programmers.stackexchange.com/questions/81624/how-do-computers-work) – gnat Mar 21 '15 at 19:53

3 Answers3

8

Does firmware of a device run in the device or the device's controller?

When does firmware of a device run? Does it run if and only if the cpu sends commands and/or data to the device's controller?

It depends entriely on the device, and it's not either/or.

For example, your garden variety SATA disk drive has one or more processors of its own, and much of the disk drive's firmware is executed on those. Among other chores, the disk drive's processors are constantly monitoring the disk for errors, and reporting back to the host CPUs when requested. This is called Self-Monitoring, Analysis and Reporting Technology (SMART).

Devices can also have Option ROM which contain support code for the device that can be executed by the host CPUs.

For BIOS, is it firmware for the bare computer system. Does it run in the cpu? Does it still run after the OS fully started?

Yes, it runs on the computer CPU, but I get the impression that you think it runs in some sort of separate execution context. It's really just a library of code that the OS can call as needed to perform some sort of low level IO (BIOS stands for basic input/output system). The OS may or may not ignore the BIOS if it has some alternative library of code for the same task.

Firmware is really just a type of storage. It can contain code for use by a host CPU, it can contain code for the onboard device controllers, or it can just contain data.

Charles E. Grant
  • 16,612
  • 1
  • 46
  • 73
  • Thanks. I thought BIOS is run before booting the OS, and when OS is fully booted, BIOS is no longer running – Tim Mar 21 '15 at 23:00
  • 1
    It's not either/or. The BIOS is used at startup to get the boot program loaded. But, after the boot program is up and running, it can call subroutines stored in the BIOS for basic input output operations. For example, if the OS wants to check if a key has been pressed, it can call a subroutine stored in the BIOS that does just that. Or it may not. It may turn out that the key press read routine in the BIOS has a bug, or is inefficient, and the OS or other host program will have its own routine for the same purpose. Really, the BIOS is just a library of utility code. – Charles E. Grant Mar 21 '15 at 23:20
  • I wonder if you are being confused by an idiomatic use of the word 'run'. The BIOS is just a static block of memory. It is not itself a processor. When we say the BIOS is running, what we really mean is that the CPU is running code that it loaded from the BIOS. – Charles E. Grant Mar 21 '15 at 23:26
  • I thought BIOS means the firmware, i.e. the code/program? – Tim Mar 21 '15 at 23:44
  • 1
    Firmware is a general category of storage. It just means data or code that is stored in a medium that is seldom changed. Most commonly its stored on a ROM (read only memory) chip. BIOS is a specific example of firmware: a ROM chip on the motherboard of a personal computer which contains a library of utility subroutines. You can see a typical list of the routines here: http://en.wikipedia.org/wiki/BIOS_interrupt_call. But it's just a memory chip, and the CPU has to do the actual processing. – Charles E. Grant Mar 22 '15 at 00:08
2

I think you are treating firmware separate from software. Firmware is unlike application software stored in memory and always runs once device is powered up. That's why it is called (firm)ware. Now for your question of dose firmware run of device. yes every firmware will run on his dedicated controller.

For a hard drive and its controller and firmware, does its firmware run in its controller and if and only if the cpu reads/writes to the hard drive?

YES, It will run on its own controller.But firmware will run continuously till it powered up. It may be waiting in some infinite loop till it receives the command from CPU.

For a wireless adapter and its firmware, does its firmware run if and only if the computer is connecting or connected to the wireless internet?

Again as mentioned above firmware will run as soon as controller is powered up. It may do some certain specified actions on events received.

for BIOS, is it firmware for the bare computer system. Does it run in the cpu? Does it still run after the OS fully started?

In case of BIOS firmware is stored on BIOS but will run on CPU. A small firmware called as bootstrap loader will load BIOS firmware in RAM and CPU will start executing it till OS loads.

prasad
  • 149
  • 6
0

A "device" in general will have some sort of processor and memory. It could be small or very powerful, and the amount of memory could be small or very large. A modern solid-state drive (SSD) is essentially a computer by itself, with firmware and hardware designed to manage NAND as well as taking commands from a host computer and processing them. Firmware is code and potentially data that generally runs on the device's processor and memory. Firmware can be written to take commands for the host and perform certain operations.

I have written an article that explains more detail about firmware and how it starts here: https://medium.com/solid-state-drives-ideas-knowledge-and-development/where-firmware-begins-ssd-firmware-development-part-9-4fb9f84dd16a

A few quotes for the article

Application software generally executes on an environment that had already been “booted” from a system, typically with an operation system. For those already familiar with software application development, the main function is, in general, where everything starts. For firmware development, developers need to be aware of the boot process, from the time of power-on.

An SoC will have at least 1 CPU and various hardware components that are initiated upon power-on. The hardware components initially will run according to the rules defined by the design and generally changes behavior based on settings from firmware, via registers (see Part 4). For the CPU (at least the main one), there is a starting point. The starting point could vary based on the specification of the SoC, but there is a pre-defined instruction address that the CPU will start executing from. For example, a CPU could start executing at instruction address 0x00000000.

Within the same set of articles, you can also find more information on firmware development.

phandinhlan
  • 109
  • 1
  • 1
    I have attributed the article to you, please roll the edit back if it's not your article. Based upon the user handles, I'm reasonably certain that it is yours. –  Jun 27 '19 at 19:01