Author Topic: Generating a UUID  (Read 2705 times)

0 Members and 1 Guest are viewing this topic.

Online Siwastaja

  • Super Contributor
  • ***
  • Posts: 8183
  • Country: fi
Re: Generating a UUID
« Reply #25 on: November 25, 2023, 08:27:33 am »
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.
Code: [Select]
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.
« Last Edit: November 25, 2023, 08:35:12 am by Siwastaja »
 
The following users thanked this post: nctnico, peter-h


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf