Traditionally, firmware is CPU code that resides on a unmodifiable ROM that is necessary for a hardware device to boot and load an operating system or a binary (software) of choice. Sometimes no choice of a binary is given and one attached to the boot-portion firmware is used.
All CPUs have the classical problem in that, since they fetch instructions from memory, some sort of pre-programmed memory must exist at a fixed address when the CPU starts, so that it can do something automatically on startup. Firmware exists for this purpose. Some firmware also has code that later programs can use for services. BIOS firmware exposes many functions that DOS used for basic input and output (hence why BIOS stands for Basic Input Output System).
The distinction is not totally clear. Some (most) WLAN cards require firmware to be loaded before they will start functioning. However, usually there is a tiny firmware on the device whose job is to do nothing but accept a main "firmware" over the USB bus when the device is started by the operating system, and hand over control when it is loaded. Most people would say all of it is firmware.
Since EEPROMs and flash memory became more common, firmware usually no longer resides in an unwriteable ROM but in flash memory and can be modified. The distinction between firmware and software is blurry today with the advent of flash memory. However, one thing hasn't changed over the years and that is CPUs are still CPUs and require some code, or firmware, to be visible at startup to, well, start up.
CPUs are in more devices than ever before so developing and allowing firmware to be updated in the case of bugs is a big deal now and many hardware devices with a CPU have firmware update interfaces, sometimes undocumented.
A firmware can be used to load an OS. It can contain a boot loader or code that loads a boot loader. It is possible to store an OS image in the same location as firmware and let the boot-time code of firmware load the OS (cell phones do this). PC BIOSes as a rule do not include boot loaders. U-boot (not for PCs) is an example of a "filesystem-aware" firmware that does directly load an operating system.
FIrmwares usually do not have all the features of a full operating system because of the principle that simpler is more reliable. The simplest firmwares simply initialize a minimum of hardware, load a sector or block off of a storage device and throw execution to it. This is simple to program and therefore easy to verify as bug free. Bugs in boot time firmware particularly can spell disaster for a device.
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.
Best Answer
Firmware and Middleware are simple industry terms to describe a certain set of 'some code'.
Firmware (as wiki states) 'usually' represents software 'usually' written in assembly or C that 'usually' runs on/the hardware.
The 'on/the' is to indicate that this software resides on a permanent storage medium (like some sort of small flash) that is directly connected to the hardware the software is to control. It's called 'firmware' because it is software specifically designed to run the hardware.
I also quote the word usually because the tech industry has a horrible habit of coining terms and then warping them so that no one can know what the true intention of the word is. 'Embedded programming' is a good current example; while the term typically referred to programmers who developed what is essentially firmware (i.e. low-level ASM/C hardware developers), the term has since morphed to include Android developers (i.e. Linux/kernel developers who can operate at both the Java and C level). I'm not bashing any sort of developer or development practice (I do a lot of those types of developing myself), merely pointing out that the tech industry likes to misuse words.
Middleware is another example of such a word; while I've yet to hear or see 'firmware' used for anything but hardware level code, I've seen middleware used on everything from firmware to .NET/Java. Middleware is a generic term that (as a developer) you usually can decipher from context what is intended as I've seen it misused too many times; so to answer you directly:
I still don't understand the differences in their roles, relative to hardware, high-level software, operating system, etc. Firmware is software (code turned to binary format) that resides on a certain piece of hardware and runs said hardware. Middleware can be used to mean an API/library that interacts with hardware (or another piece of software for that matter).
Is BIOS firmware not middleware? Depending on your view of this, it could be both. Technically the BIOS is firmware (it's software that is specifically used to run the hardware it's on, i.e. the motherboard), but if your intent is to interact directly with a piece of hardware in some fashion (as an OS would), the BIOS 'could' be middleware, as you don't have to 'write' your own BIOS and hardware routines and this is where the misuse of 'middleware' can come in, but in a classical since, no the BIOS is not middleware.
Is a bootloader for an OS a firmware, middleware or someware? A bootloader for an OS is a piece of code that resides between the BIOS (or other basic hardware subsystem) and the higher level systems (usually the OS) that tells the lower systems (i.e. BIOS) where the OS resides on the boot medium. Typically speaking, a bootloader usually sits on a specific location of a storage medium (like the first few hundred bytes or more) and the BIOS knows (thanks to industry standards) where to 'look' for a bootloader at which point the bootloader takes over to do what it was written to do (usually boot the OS).
A bootloader is not firmware but could technically reside in firmware and as far as it being 'middleware', that could be yes or no depending on 'your' view of what 'middleware' is/should be, though in the classical since of middleware, I would not consider a bootloader middleware as it doesn't provide me any easier context (unless I'm writing an OS).
Is the instruction set of a CPU firmware and not middleware? An instruction set of a CPU would be considered more of an application programming interface (API) (which 'could' be considered a form of middleware), it is not firmware as the CPU (the central processing unit itself) doesn't have anything 'to run'; the CPU instruction set is what the software gets 'compiled' to (assembly) that the CPU then 'understands' how to run.
Is there some middleware not firmware? Yes; just about any software framework you can think of (the .NET or Java libraries for example) could be considered a form of middleware as they give a programmer an 'easier' way to interact with various aspects of a computer. Using Java, for instance, you could open a file and write to it and have that code 'work' on any Java supported system. Since certain Java API's let you have a few lines of code that interact with files across disparate systems, it can be considered a form of 'middleware' since the developer doesn't have to write the code for each different system (Linux/Windows/Apple,etc) to interact with the filesystem of the hard drive and OS him/herself.
What are the relations and differences between device drivers and firmware and middleware? A device driver is a piece of software that sits at the OS level (usually as an 'installed' library) that tells the OS 'how' to interact with said device. For instance, when you install the latest video drivers, you are installing software that the OS 'uses' to communicate with the actual video card itself. The video card itself has firmware on it that knows how to interpret the information given it to by the OS (because of the driver) and does what it will with it (draw a window or game sprite for instance).
Device drivers could be considered middleware (again depending on your view of such) since it sits between the OS/hardware and anyone wanting to use the hardware through the OS.
Anecdotal: in my industry experiences, I have found 'middleware' to 'mean' 'web services' or something of the like (at least what the person using the term is meaning anyways), though I have also seen/heard it (mis)used in many job postings and interviews to mean a variety of things from API's and libraries (like Boost or Spring) to the C++ STL and even C# itself (the language itself, not .NET).
I hope that can help.