One of the big difference between IoT devices and software is that IoT devices are manufactured. Manufacturing processes focus on consistency and reproducibility; all variations must be eliminated.
Once the hardware is assembled, the firmware must be written to the device. Usually, this is done in one of three ways: during testing, using pre-programmed chips, or during chip manufacturing.
During manufacturing, a hardware assembly will undergo basic electrical testing. Usually this is achieved by putting the assembly into a test jig, connecting to test points on the assembly with pogo pins, and checking that various signals and voltages on the board are within tolerance. Assemblies that fail these checks are returned for rework or discarded.
This is a convenient time to write firmware to the device. This happens automatically if the device passes electrical testing. It costs a few seconds to a minute, depending on the design of the device.
Often, a small bootstrap firmware image is all that is written. Test jig time is expensive and it’s slow to write large amounts of data. It’s also difficult to change the firmware image after the manufacturing line is set up. From a project management point of view, a late firmware project doesn’t delay setup of the manufacturing line. So a minimal bootstrap image is written through the jig, and final production firmware (including any updates) is written at a later stage.
This is the most common way to get initial firmware onto a device.
Most devices use blank off-the-shelf chips and write their own image to them. Sometimes, it’s easier to program the chips before assembly onto the PCB. This might be done as an in-house manufacturing step using a dedicated device programmer, or it might be done by a third party (usually the chip manufacturer). The same guidelines as above apply:
This is mostly used when you have a stable, high-volume product.
Many modern CPUs, SoCs and microcontrollers have bootloaders built in. Some of these are remarkably sophisticated, able to interface with MicroSD storage, parse FAT filesystems or communicate over network interfaces.
If you’re custom-building your SoC (say, for hidden crypto/trust modules) then you’re in a good position to bake in a bootloader that works for your hardware platform and thus save some manufacturing time.
You might not need to write firmware to the device at all until just before it’s shipped.
Manufacturing processes are driven by two concerns:
At the end of the manufacturing process, every single device is identical. Any variation – except in very specific, controlled ways, such as a unique ID chip – is considered waste and must be eliminated.