Depending on the sector where you are in, there are slightly different definitions. In digital VLSI design, an embedded system is a system inside a chip. A system refers to one or more controller(s) or processor(s)that have a connection (data and control) to other parts of the system. These other parts can be on-chip memory (ROM, RAM, flash, OTP) , off-chip (DDR SRAM), debug and test interfaces (JTAG), communication interfaces (UART, USB, ethernet, …), … . Firmware is embedded software, this means the code that runs inside the embedded system on the embedded processor. An example is a system on chip that acts as a USB device needs to have the USB stack implemented to be able to connect to a USB host (enumeration) and transfer data after enumeration. A bootloader is hard coded into the chip and defines what the user can put/develop on the chip as embedded software. Middleware is, to my understanding, an even more fuzzy term. It is used in computer networks for the layer between data and the application. In a system on chip, it is less used but as Felmming Steffensen says, it can be used as an abstraction layer, that hides the hardware specific stuff. The same USB driver can be called middleware since the HAL, the hardware abstraction layer is the layer that hides the actual register accesses, status and control, for a certain hardware part. In the USB example, the USB controller and the USB PHY (physical frontend) can be from different vendors or IP suppliers. The adress space and the control and status bits are not necessarily 100% identical. Hence the HAL implements the specific register accesses for a specific brand or vendor. On the layer above, the HAL offers a uniform way of access, functions to send a token, receive a token, return pass or fail for a received token. When changing controller, only the HAL needs to be changed, the rest of the application software above it, stay the same.
Hardware and software advisor for tech startups. ASIC, FPGA, RPi, Arduino, AI, robots, drones, blockchain, Machine learning, vision processing, IoT and 3D printers are my fields of expertise.