A Python tool:
Or, from a makefile or bash script, after installing srec_cat, something like this. This example adds a 32-bit value stored in makefile variable $(devid) to address 0x10001080, combining that with existing whole.hex, to produce out.hex.
printf "%s" "${devid}" | fold -w 2 | tac | xxd -r -p - > tmp.bin
$(OBJCOPY) --change-addresses 0x10001080 -I binary -O ihex tmp.bin tmp2.hex
srec_cat whole.hex -intel tmp2.hex -intel -o out.hex -intel
First line converts the hexadecimal string (e.g. $devid=acdcabba) to 4-byte little endian binary file: printf echoes the hexadecimal string, fold divides it two characters (one byte) per each line, tac reverses the line order (for little endianness), and xxd -r converts from ascii hexadecimal to binary.
Second line converts the binary value to .hex, adding an address to it (addresses are a feature of .hex files).
Third line combines that hex with another hex. The weirdest thing in srec_cat is the command line syntax where you first give the filename then the format. Something like srec_cat or the python library as shown above is needed, as .hex files are sparse and contain address meta information, therefore they cannot be combined by simple means like concatenation of two hex files.