Say you make a system/gadget with a Pi and a bunch of sensors that the Pi gathers data from. Is the software on the Pi reading the data count as firmware? or the Raspbian OS itself?
I would say no, although the concept is I think abstract enough that depending on the specifics of the context it might be considered such -- why and when to use such a label may be more about convention rather than any strict legal definition. A defining characteristic might be considered the fact that firmware often operates from non-volatile memory (NVM), that is, memory which "can retain stored information even after power is removed", but while "historically, firmware were [sic] built-into the device's ROM or Flash memory", this is not necessarily the case today (see comments below for examples), and while NVM categorically includes storage (such as an SD card), code that resides on storage (such as the entire OS) is generally not firmware: Another provisional distinction or definition of firmware vs. software might be that software is loaded into system RAM and executes from there under the supervision of the operating system, while firmware is more likely to be loaded into a device's own memory and run by it largely independent of, although of course in service to, the operating system. For normal software, the kernel is intermediary between it and any hardware, a sort of inversion of this role (firmware services the kernel, the kernel services userland software).1
Drivers are kernel space code that (amongst other things) may load firmware (eg., on linux, the stuff in
/lib/firmware) from storage into a device's own RAM (eg. graphics cards) or NVM. What does set firmware apart is that it probably does not run from system RAM, since this would make it dependent on the OS kernel and the various pitfalls of a multi-tasking environment (while devices that can exploit direct memory access may use firmware to do it, I think the system RAM would be used to hold data more than code).
However, on the Pi the GPU firmware is stored on the boot partition of the SD card, which is initialized by the GPU and the code run from GPU memory -- which of course is just a share of the board RAM, although since that is a hardware configuration set before the OS boots, the GPU portion would not really be "system memory".
- This definition would exclude userland code that reads sensors via the system (including the use of
mmap, which is what Pi-specific GPIO libraries usually do) from being considered "firmware".